Support buffering request body (RequestBodyBufferMiddleware)#216
Support buffering request body (RequestBodyBufferMiddleware)#216WyriHaximus merged 4 commits intoreactphp:masterfrom
Conversation
tests/Middleware/BufferTest.php
Outdated
| public function testToLargeBody() | ||
| { | ||
| $size = $this->iniMaxPostSize() + 1; | ||
| $stream = new BufferStream($size); |
There was a problem hiding this comment.
Not sure what's supposed to be tested here? Afaict this should probably use a fixed limit instead?
|
|
||
| if ($size === null) { | ||
| return new Response(411, array('Content-Type' => 'text/plain'), 'No Content-Length header given'); | ||
| } |
There was a problem hiding this comment.
Makes perfect sense to me, but we should probably add some documentation and tests for this 👍
For the reference: I've discussed this with @WyriHaximus and I think it's save to say we all agree that it may make sense to also support incoming requests with Transfer-Encoding: chunked in a future version (follow-up PR) 👍 This feature is rarely used in the real world and not something that will be needed for most people (unlike outgoing responses with Transfer-Encoding: chunked which are supported).
| { | ||
| private $sizeLimit; | ||
|
|
||
| public function __construct($sizeLimit = null) |
There was a problem hiding this comment.
Could use some documentation about the expected parameter type 👍
src/Middleware/Buffer.php
Outdated
| use React\Stream\ReadableStreamInterface; | ||
| use RingCentral\Psr7\BufferStream; | ||
|
|
||
| final class Buffer |
There was a problem hiding this comment.
Not sure about the name, as new Buffer() doesn't really convey its responsibility? How about something like RequestBufferer (which doesn't sound perfect either).
There was a problem hiding this comment.
RequestBodyBuffer could work.
There was a problem hiding this comment.
Sounds much better to me, so I won't block this 👍
To be this name still implies this class represents the buffer itself, while it is actually (only) responsible for the buffering process and storing the complete buffer back into the request instance that will be passed upstream.
I guess this class could use some documentation? :-)
| { | ||
| private $sizeLimit; | ||
|
|
||
| public function __construct($sizeLimit = null) |
There was a problem hiding this comment.
Could use some documentation about the expected parameter type 👍
| public function testToLargeBody() | ||
| { | ||
| $size = $this->iniMaxPostSize() + 1; | ||
| $stream = new BufferStream($size); |
There was a problem hiding this comment.
Not sure what's supposed to be tested here? Afaict this should probably use a fixed limit instead?
There was a problem hiding this comment.
Replaced that tests with one specifically for the 413 error
|
|
||
| if ($size === null) { | ||
| return new Response(411, array('Content-Type' => 'text/plain'), 'No Content-Length header given'); | ||
| } |
There was a problem hiding this comment.
Makes perfect sense to me, but we should probably add some documentation and tests for this 👍
There was a problem hiding this comment.
And added docs for it
src/Middleware/RequestBodyBuffer.php
Outdated
| } | ||
|
|
||
| return $size; | ||
| throw new \UnexpectedValueException('post_max_size value is out of range.'); |
There was a problem hiding this comment.
This will now throw for a size specified in bytes (without a suffix)
There was a problem hiding this comment.
Good point, I've reverted it
|
Thanks! Ping @clue :P |
949b061 to
0bbc802
Compare
0bbc802 to
4c4e950
Compare
4c4e950 to
c8d66b8
Compare
clue
left a comment
There was a problem hiding this comment.
Nice! 🎉 I've rebased and squashed some of your changes and updated the documentation to describe streaming<->buffered request handling, otherwise looks good to me functionally 👍 If you're okay with my changes, let's get this in! ![]()
WyriHaximus
left a comment
There was a problem hiding this comment.
Cool, changes look good 👍
Buffer Middleware split off from #213
Assumes to be used with #215